package Main;


import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.concurrent.locks.ReentrantLock;

import FileIO.IO;
import Greedy_Snake_Map.MMap;
import Greedy_Snake_Map.Map_Type;
import Greedy_Snake_Map.Time;
import Mouse_key_Event.Key;
import snake.Snake_body;

public class Main {
	public static void Game(Snake_body csnake) {
		// TODO 自动生成的方法存根
		System.out.println("Main");
		
		Snake_body snake;
		if(csnake==null)
		{
			snake=new Snake_body(); 
		}
		else 
		{
			snake=csnake;
		}
		Main_Frame mscreen=new Main_Frame(snake);//主窗口
		doWinHandle dowinhandle=new doWinHandle();//主窗口的x的监听器
		mscreen.addWindowListener(dowinhandle);
		dowinhandle.set_snake(snake);
		
		mainPanel panel=mscreen.getpanel();//中心面板
		Key code_key=new Key(mscreen);//键盘监听
		panel.addKeyListener(code_key);
		panel.requestFocus();//中心面板获取键盘焦点
		Time timer=new Time(Main_Frame.get_ScrollPane(),snake,panel);//计时器 刷新滚轮面板的
	}

}
class doWinHandle implements WindowListener {
	Snake_body snake;
	public void set_snake(Snake_body snake)
	{
		this.snake=snake;
	}
	public void windowOpened(WindowEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO 自动生成的方法存根
		FileIO.IO.OUT(snake);
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO 自动生成的方法存根
		
	}
	
}
